import moment from 'moment'

export const DateFormat = {
    Day: 'YYYY-MM-DD',
    Day1: 'YYYYMMDD',
    Minute: 'YYYY-MM-DD HH:mm',
    Second: 'YYYY-MM-DD HH:mm:ss',
    SecondEnStr: 'YYYYMMDDHHmmss',
    SecondChStr: 'YYYY年MM月DD日 HH:mm:ss',
    Time: 'HH:mm:ss',
};

export const DayMillisecond = 24 * 60 * 60 * 1000;
export const DaySecond = 24 * 60 * 60;

export const TimeString = {
    TimeStart: ' 00:00:00',
    TimeEnd: ' 23:59:59',
};

//使用上面的替换
export const Day = 'YYYY-MM-DD';
export const Minute = 'YYYY-MM-DD HH:mm';
export const Second = 'YYYY-MM-DD HH:mm:ss';
export const SecondString = 'YYYYMMDDHHmmss';
export const MSecondString = 'yyyyMMDDHHmmssSS';
export const Time = 'HH:mm:ss';

export default class DateUtils {
    /**
     * 将标准时间转换成时间字符串
     * @param date
     * @param format
     * @returns {*}
     */
    static dateToString = (date, format) => {
        if (!date) {
            return ''
        }
        let stamp = parseInt(date);
        if (isNaN(stamp)) {
            stamp = date;
        }
        let timeStr = moment(stamp).format(format);
        // console.log('dateToString', stamp, timeStr);
        return timeStr;
    };

    /**
     * 获取当天时间的YYYY-MM-DD 00:00:00的字符串
     */
    static getTodayStartTime() {
        return this.dateToString(new Date(), DateFormat.Day) + ' 00:00:00'
    }

    /**
     * 获取当前时间的YYYY-MM-DD 00:00:00的字符串
     */
    static getNowTime() {
        return this.dateToString(new Date(), DateFormat.Second);
    }

    /**
     * 获取当月的第一天的日期
     */
    static getMonthStartDate() {
        let nowTime = new Date();
        return nowTime.getFullYear() + '-' + (nowTime.getMonth() + 1) + '- 01';
    }

}
